#pragma once

#include <gofcl_usbfs_dcfg.h>

typedef enum {
	USBFS_DS_FULL_SPEED = 3,
} usbfs_ds_e;

typedef enum {
	USBFS_EOPFT_80_PERCENT = 0,
	USBFS_EOPFT_85_PERCENT = 1,
	USBFS_EOPFT_90_PERCENT = 2,
	USBFS_EOPFT_95_PERCENT = 3,
} usbfs_eopft_e;

typedef struct {
	usbfs_ds_e speed : 2;
	u32_s non_zero_len_pkt_stall_en : 1;
	u32_s : 1;
	u32_s dev_addr : 7;
	usbfs_eopft_e periodic_frame_end_time : 2;
	u32_s : 19;
} usbfs_dcfg_expl_s;

_Static_assert(sizeof(usbfs_dcfg_expl_s) == 4,
	       "Struct usbfs_dcfg_expl_s defined error!");

static inline void usbfs_set_dev_cfg_s(usbfs_dcfg_expl_s dcfg) {
	union {
		usbfs_dcfg_expl_s e;
		usbfs_dcfg_s d;
	} du = {
		.e = dcfg,
	};
	usbfs_wreg_dcfg_s(du.d);
}

static inline usbfs_dcfg_expl_s usbfs_get_dev_cfg_s(void) {
	union {
		usbfs_dcfg_expl_s e;
		usbfs_dcfg_s d;
	} gu = {
		.d = usbfs_rreg_dcfg_s(),
	};
	return gu.e;
}
